title = "分类详情页"
url = '/:slug|[a-z0-9\-]+-c-\d+.html$'
title = '分类详情页模板'
layout = 'default'
==

use Jason\Ccshop\Controllers\Filters;
use Jason\Ccshop\Controllers\Categories;
use Jason\Ccshop\Models\Category;
use Jason\Ccshop\Models\Product;
function onStart(){
	$slugArr = explode('-', str_replace('.html','', $this->param('slug')));
    $slug = str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), $this->param('slug'));
	$id = array_pop($slugArr);
	array_pop($slugArr);
	$condition = ['id' => $id];

	$this['paramKey'] = join('-', $slugArr);
	$categoryModel = Category::where('id', $id)->first();

	$this['currentUrl'] = str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), substr(request()->getRequestUri(),1));
	$this['sortFlag'] = $slugArr[0];

	if(!$categoryModel) {
		return redirct('/404');
	}
	$this['category'] = $categoryModel;
	//dd($this['category']);

	$pids = get('id_sort')?get('id_sort'):null;
	$pageNumber = get('page')?get('page'):1;

	if(!empty($pids)){
		Cookie::queue('idssort',$pids);
		Cookie::queue('cid',$id);
		Cookie::queue('pagenumber',$pageNumber);
	}else{
		$pageNumber = Cookie::get('pagenumber');
		$cid = Cookie::get('cid');
		$currentPage = get('page')?get('page'):1;
		if($currentPage==$pageNumber && $id==$cid){
			$pids = Cookie::get('idssort');
		}
	}

	if (!empty($pids)) {
		$pida = explode(',',$pids);
		$pd = Product::InStock()->whereIn('id',$pida)->get();
		$this['adproducts'] = $pd;
		$this['pida'] = $pida;
	}

	if ($this['paramKey'] != $categoryModel['slug']) {
		$paramKey = explode('-',$this['paramKey']);
		$orderArr = Filters::parseFilterKeyParams($paramKey[0]);
		if (count($orderArr) == 2) {
			$order = [$orderArr[0] => $orderArr[1]];
		}
	}
	$this['order'] = isset($order) ? $order : ['sort' => 'asc'];
	$this['products'] = App::make('Jason\Ccshop\Controllers\Products')->getCategoryProducts($categoryModel->id, $this['order']);

	//$a =App::make('Jason\Ccshop\Components\Catalog')->categories();
	//dd($a);
}
==

{% set categories = catalog.categories %}
{% put page_title %}{{ category.page_title }}{% endput %}
{% set per = get('per', 20) %}
{% put pageurl %}{{ catalog.canonicalValue(category.url, 'category')|raw }}{% endput %}

{% put pageUrl %}
<link rel="canonical" href="{{ ''|page }}">
{% if products.nextPageUrl %}

<link rel="next" href="{{ products.nextPageUrl }}">

{% endif %}
{% endput %}

{% put meta_keywords %}{{ category.meta_keywords }}{% endput %}
{% put meta_description %}{{ category.meta_description }}{% endput %}
{% if count(adproducts) > 0 %}
<div class="indexTjThree" style="">
	<div class="swiper-container indexTjThree_swipe swiper-container-horizontal">
	    <div class="swiper-wrapper">

	        {% for adproduct in adproducts %}
				<div class="swiper-slide ">
					<a href="{{ adproduct.url }}" style="display: block;margin: 0 5px;">
						<div class="posiR">
							{% for img in adproduct.feature_image %}
							{% if loop.index == 1%}
							<img src="{{ img.path }}" alt="{{adproduct.name}}">
							{% endif %}
							{% endfor  %}
						</div>
				    	<div class="contBlock">
							<p class="txtGray1 Ellipsis">{{ adproduct.name }}</p>
							<p class="txtGray"><b>{{ adproduct.price|formatPrice }}</b></p>
						</div>
					</a>
				</div>
			{% endfor %}

			{% for key, val in catalog.productSection('m-promote-product', products.data[0].id).items %}
			{% if val.id not in pida %}
			<div class="swiper-slide" style="margin-left:0;">
				<a href="{{ val.url }}" style="display: block;margin: 0 5px;">
					<div class="posiR">
						{% for img in val.feature_image %}
						{% if loop.index == 1%}
						<img src="{{ val.f_thumb }}" alt="{{val.name}}">
						{% endif %}
						{% endfor  %}
					</div>
					<div class="contBlock">
						<p class="txtGray1 Ellipsis">{{ val.name }}</p>
						<p class="txtGray"><b>{{ val.price|formatPrice }}</b></p>
					</div>
				</a>
			</div>

			{% endif %}
			{% endfor %}
    	</div>
    	<!--  -->
	    <div class="swiper-button-prev" style="margin-top: -54px;"></div>
	    <div class="swiper-button-next" style="margin-top: -54px;"></div> 
	</div>
</div>
{% endif %}
<div class="category_content">
	<!--<div style="overflow: hidden;margin: 5px 0 10px;">-->
		<!--<p class="allItemNum"> 全{{ products.total }} 商品 </p>-->
		<!--{{ products.render|raw }}-->
	<!--</div>-->
	<!--{% partial 'catalog/list-toolbar' products = products.data %}-->
	{% partial 'common/breadCrumb' %}
	<div class="">
		<h3 class="title_line">
			{{category.name}}
		</h3>
		<div class="" style="text-align: center;margin: 10px 0 15px 0;">
			<select id="hiddenselect" name="S1" style="border: 1px solid #A7A7A7;width: 90%;padding: 4px 0;color: #615f5f;" onChange="window.open(this.value,'_self')">
				{% if count(category.children)>= 1 %}
					{% for getchildren in category.children %}
						{% if getchildren.is_enabled==1 %}
							<option value="{{ getchildren.url }}">{{ getchildren.name }}</option>
						{% endif %}
					{% endfor %}
				{% elseif count(category.children)== 0 %}
					{% for subcate in categories %}
						{% if subcate.id == 5 %}
							{% for subcd in subcate.children %}
								{% if subcd.id == category.parent_id %}
									{% for sssubcd in subcd.children %}
										{% if sssubcd.is_enabled==1 %}
										<option value="{{ sssubcd.url }}">{{ sssubcd.name }}</option>
										{% endif %}
									{% endfor %}
								{% endif %}
							{% endfor %}
						{% endif %}
					{% endfor %}
					{% for subcate in categories %}
						{% if subcate.id != 5 %}
							{% if subcate.id == category.parent_id %}
								{% for sssubcd in subcate.children %}
									{% if sssubcd.is_enabled==1 %}
									<option value="{{ sssubcd.url }}">{{ sssubcd.name }}</option>
									{% endif %}
								{% endfor %}
							{% endif %}
						{% endif %}
					{% endfor %}
				{% endif %}			  	
			</select>
		</div>
		<div class="itemList">
			<ul class="listUl">
				{% for product in products.data %}
				<li class="product_h">
					<a href="{{ product.url }}">
						<div class="productImg">
							<img src="{{ product.f_thumb }}" alt="{{ product.name }}" class="productImgH">
							{% if product.saled > 500 %}
							<span class="hotSale sale_"><img src="{{ 'assets/img/hotSale.png'|theme }}" alt=""></span>
							{% endif %}
							{% if product.labels == "newest" %}
							<span class="newSale sale_"><img src="{{ 'assets/img/newSale.png'|theme }}" alt=""></span>
							{% endif %}
						</div>
						<div class="contBlock">
							<p class="txtGray1 Ellipsis">{{product.name}}</p>
							<p class="txtGray"><b>{{ product.price|formatPrice }}</b>税込 &nbsp;
								{% if product.discount %}
								<span class="proSale"><b>-{{ product.discount }}</b></span>
								{% endif %}
							</p>
							
							<p class="txtGray" style="height: 18px;">
								{% if product.reviews_total > 0 %}
								<a href="{{ product.url }}#categoryReviews" style="height:18px;line-height:18px;text-align:right;">レビュー({{ product.reviews_total }})</a>
								{% endif %}
							</p>							
	
						</div>
					</a>
				</li>
				{% endfor %}
				
			</ul>
		<div style="overflow: hidden;margin: 5px 0 10px;">
			<p class="allItemNum"> 全{{ products.total }} 商品 </p>
			{{ products.render|raw }}
		</div>
		</div>		
	</div>
</div>

{% partial 'index/index_login' %}

{% for key, product in products.data %}
  {% put google_tag_params %}
  var google_tag_params = {
    ecomm_prodid: "{{product.id}}",
    ecomm_pagetype: "category",
    ecomm_totalvalue: {{product.price|ratePrice}}
  };
  {% endput %}
{% endfor %}